//自定参数校验逻辑
const validator = require("./Errback");
const { Video } = require("../../model");
const { body } = require("express-validator"); // body获取post参数

//注册参数校验
module.exports.createVideos = validator([
    body('title').notEmpty().withMessage('标题不能为空!').bail()
    .custom(async val=>{
        const titleValidator = await Video.findOne({title:val})
        if(titleValidator){
            return Promise.reject('标题已经存在!!!')
        }
    }).bail(),
    body('vodvideoId').notEmpty().withMessage('vodvideoId不能为空!').bail()
    .custom(async val=>{
        const vodvideoIdValidator = await Video.findOne({vodvideoId:val})
        if(vodvideoIdValidator){
            return Promise.reject('vodvideoId已经存在!!!')
        }
    }).bail()
])

